#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e6+10;
int num[maxn];
int mp[maxn];
int flag[maxn];
int ss;
int init(int a,int b)
{
	int x = a*10+b;
	memset(mp,0,sizeof(mp));
	mp[x]++;
	flag[x] = 0;
	int cnt = 0;
	num[cnt++] = a;
	num[cnt++] = b;
	while(mp[x]<2)
	{
		x = num[cnt-1]*num[cnt-2];
		if(x<10) num[cnt++] = x;
		else 
		{
			num[cnt++] = x/10;
			num[cnt++] = x%10;
		}
		x = num[cnt-1]+num[cnt-2]*10;
		mp[x]++;
		if(mp[x]==1) flag[x] = cnt-2;
		if(mp[x]==2) ss = x;
	}
	return cnt;
}
int main()
{
	int k;
	cin>>k;
	while(k--)
	{
		int a,b,q;
		cin>>a>>b>>q;
		int mod = init(a,b);
		mod -= (flag[ss]+2);
		for(int i = 0;i<q;i++)
		{
			int n;
			cin>>n;
			if(ss==0)
			{
				if(n-1<flag[ss]) cout<<num[n-1]<<endl;
				else cout<<0<<endl;
			}
			else 
			{
				if(n-1<flag[ss]+1) cout<<num[n-1]<<endl;
				else 
				{
					n = n-flag[ss]-2;
					cout<<num[(n%mod)+flag[ss]+1]<<endl;
				}
			}
		}
	}
}
